<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p>年：<input type="text" id="year"></p>
    <p>月：<input type="text" id="month"></p>
    <p>日：<input type="text" id="day"></p>
    <p><button id="btn">判断</button></p>
    <p><input type="text" id="result" disabled></p>
    <p><input type="text" id="result1" disabled></p>

</body>
<script>
    var yearInp = document.getElementById("year");
    var monthInp = document.getElementById("month");
    var dayInp = document.getElementById("day");
    var btn = document.getElementById("btn");
    var resultInp = document.getElementById("result");
    var result1Inp = document.getElementById("result1");
    console.log(year, month, day, btn, result, result1);
    btn.onclick = function () {
        var year = Number(yearInp.value);
        var month = Number(monthInp.value);
        var day = Number(dayInp.value);
        var num = 0;
        if (year < 1000 || year > 9999 || year % 1 != 0) {
            alert("请输入1000-9999之间的整数年份。");
        } else {
            resultInp.value = year + "年";
        }
        if (month >= 1 && month <= 12 && month % 1 == 0) {
            resultInp.value = year + "年" + month + "月";
        } else {
            alert("请输入1-12之间的整数月份。");
        }
        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
            if (day >= 1 && day <= 31) {
                resultInp.value = year + "年" + month + "月" + day + "日";
            } else {
                alert("日期请输入1-31");
            }
        } else if (month == 4 || month == 6 || month == 9 || month == 11) {
            if (day >= 1 && day <= 30) {
                resultInp.value = year + "年" + month + "月" + day + "日";
            } else {
                alert("日期请输入1-30");
            }
        } else {
            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                if (day >= 1 && day <= 29) {
                    resultInp.value = year + "年" + month + "月" + day + "日";
                } else {
                    alert("日期请输入1-29");
                }
            } else {
                if (day >= 1 && day <= 28) {
                    resultInp.value = year + "年" + month + "月" + day + "日";
                } else {
                    alert("日期请输入1-28");
                }
            }
        }
        // resultInp.value = year + "年" + month + "月" + day + "日";
        if (resultInp.value == year + "年" + month + "月" + day + "日") {
            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
                switch (month) {
                    case 1: num = month * 31 - 31; break;
                    case 2: num = month * 31 - 31; break;
                    case 3: num = month * 31 - 31 - 2; break;
                    case 4: num = month * 31 - 30 - 2; break;
                    case 5: num = month * 31 - 31 - 2 - 1; break;
                    case 6: num = month * 31 - 30 - 2 - 1; break;
                    case 7: num = month * 31 - 31 - 2 - 2; break;
                    case 8: num = month * 31 - 31 - 2 - 2; break;
                    case 9: num = month * 31 - 30 - 2 - 2; break;
                    case 10: num = month * 31 - 31 - 2 - 3; break;
                    case 11: num = month * 31 - 30 - 2 - 3; break;
                    case 12: num = month * 31 - 31 - 2 - 4; break;
                }
            } else {
                switch (month) {
                    case 1: num = month * 31 - 31; break;
                    case 2: num = month * 31 - 31; break;
                    case 3: num = month * 31 - 31 - 3; break;
                    case 4: num = month * 31 - 30 - 3; break;
                    case 5: num = month * 31 - 31 - 3 - 1; break;
                    case 6: num = month * 31 - 30 - 3 - 1; break;
                    case 7: num = month * 31 - 31 - 3 - 2; break;
                    case 8: num = month * 31 - 31 - 3 - 2; break;
                    case 9: num = month * 31 - 30 - 3 - 2; break;
                    case 10: num = month * 31 - 31 - 3 - 3; break;
                    case 11: num = month * 31 - 30 - 3 - 3; break;
                    case 12: num = month * 31 - 31 - 3 - 4; break;
                }
            }
            num += day;
            result1Inp.value = "今天是本年第" + num + "天";
        } else {
            result1Inp.value = "";
        }


    }

</script>

</html>